package com.yspa.bloodSugar.dao.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.dao.HibernateSqlUtil2;
import com.hsnn.medstgmini.util.Pagination;
import com.yspa.bloodSugar.dao.BloodSugarDao;

@Repository
public class BloodSugarDaoImpl implements BloodSugarDao {

	@Autowired
	private HibernateSqlUtil dao;
	@Autowired
	private HibernateSqlUtil2 sqldao;
	public Pagination getBloodSugarList(Pagination page){
		StringBuffer sql = new StringBuffer();
		sql.append("select * from blood_sugar")
		.append(" where 1=1 ");
		Map<String, Object> params = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(page.getConditions().get("title"))){
			sql.append(" and title like :title");
			params.put("title", "%" + page.getConditions().get("title").trim() + "%");
		}
		
		String ssql = "select * from Abnormal";
		Pagination pp = new Pagination();
		pp.setFirstResult(5);
		pp.setMaxResults(2);
		Pagination p = sqldao.getPageMapList(ssql, null, pp);
		List<Map<String, Object>> ll = (List<Map<String, Object>>) p.getRows();
		for (int i = 0; i < ll.size(); i++){
			Map<String, Object> map = ll.get(i);
			Iterator<?> mlist = map.entrySet().iterator();
			while (mlist.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) mlist.next();
				System.out.println(entry.getKey()+": " + map.get(entry.getKey()));
			}
			System.out.println("-----------------------------------------------------------------------");
		}
		
		
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public List getDataInfo(String id){
		String sql = "select * from blood_sugar where id=:id";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		return dao.getSqlMapList(sql, params);
	}
}
